# -*- coding: utf-8 -*-
"""
:mod:`nubio.data.alphabet`
==========================

The ``nubio.data.alphabet`` module provides biological alphabets as ``tuples``
of ``NuBox`` items. See: ``nubox.char.Char``.

"""

# SYMBOLS
GAP_IUPAC = (('-',),)
GAP_ABUSE = (('.',),)
GAP = GAP_IUPAC + GAP_ABUSE
STOP_IUPAC = (('*',),)
STOP_ABUSE = ()
STOP = STOP_IUPAC + STOP_ABUSE
MISSING_IUPAC = (('?',),)
MISSING_ABUSE = ()
MISSING = MISSING_IUPAC + MISSING_ABUSE

# AA
AA_STANDARD_IUPAC = (('A',), ('C',), ('D',), ('E',), ('F',), ('G',), ('H',),
                     ('I',), ('K',), ('L',), ('M',), ('N',), ('P',), ('Q',),
                     ('R',), ('S',), ('T',), ('V',), ('W',), ('Y',))
AA_NONSTANDARD_IUPAC = (('O',), ('U',))
AA_AMBIGUOUS_IUPAC = (('B',), ('J',), ('X',), ('Z',))
AA_IUPAC = AA_STANDARD_IUPAC + AA_NONSTANDARD_IUPAC + AA_AMBIGUOUS_IUPAC
AA_ABUSE = ()
AA = AA_IUPAC + AA_ABUSE
AA_IUPAC_ALPHABET = AA_IUPAC + STOP_IUPAC + GAP_IUPAC + MISSING_IUPAC
AA_ALPHABET = AA + STOP + GAP + MISSING

# DNA
DNA_STANDARD_IUPAC = (('T',), ('C',), ('A',), ('G',))
DNA_AMBIGUOUS_IUPAC = (('B',), ('D',), ('H',), ('K',), ('M',), ('N',), ('R',),
                       ('S',), ('V',), ('W',), ('Y',))
DNA_IUPAC = DNA_STANDARD_IUPAC + DNA_AMBIGUOUS_IUPAC
DNA_ABUSE = (('X',))
DNA = DNA_IUPAC + DNA_ABUSE
DNA_IUPAC_ALPHABET = DNA_IUPAC + GAP_IUPAC + MISSING_IUPAC
DNA_ALPHABET = DNA + GAP + MISSING

# RNA
RNA_STANDARD_IUPAC = (('U',), ('C',), ('A',), ('G',))
RNA_AMBIGUOUS_IUPAC = (('B',), ('D',), ('H',), ('K',), ('M',), ('N',), ('R',),
                       ('S',), ('V',), ('W',), ('Y',))
RNA_IUPAC = RNA_STANDARD_IUPAC + RNA_AMBIGUOUS_IUPAC
RNA_ABUSE = (('X',))
RNA = RNA_IUPAC + RNA_ABUSE
RNA_IUPAC_ALPHABET = RNA_IUPAC + GAP_IUPAC + MISSING_IUPAC
RNA_ALPHABET = RNA + GAP + MISSING

# NT
NT_STANDARD_IUPAC = tuple(sorted(set((DNA_STANDARD_IUPAC +
                                      RNA_STANDARD_IUPAC))))
NT_AMBIGUOUS_IUPAC = tuple(sorted(set((DNA_AMBIGUOUS_IUPAC +
                                       RNA_AMBIGUOUS_IUPAC))))
NT_IUPAC = NT_STANDARD_IUPAC + NT_AMBIGUOUS_IUPAC
NT_ABUSE = tuple(sorted(set((DNA_ABUSE + RNA_ABUSE))))
NT = NT_IUPAC + NT_ABUSE
NT_IUPAC_ALPHABET = NT_IUPAC + GAP_IUPAC + MISSING_IUPAC
NT_ALPHABET = NT + GAP + MISSING
NT_COMPLEMENT_STANDARD_IUPAC = dict([((i,), (j,)) for i, j in \
                            zip("TCAGU", "AGTCA")])

NT_COMPLEMENT_IUPAC = dict([((i,), (j,)) for i, j in \
                            zip("TCAGURYSWKMBDHVN-?", "AGTCAYRSWMKVHDBN-?")])

# IUPAC
ANY_STANDARD_IUPAC = tuple(sorted(set(AA_STANDARD_IUPAC + NT_STANDARD_IUPAC)))
ANY_IUPAC = tuple(sorted(set(AA_IUPAC + NT_IUPAC)))
ANY_ABUSE = tuple(sorted(set(AA_ABUSE + NT_ABUSE)))
ANY = ANY_IUPAC + ANY_ABUSE
ANY_IUPAC_ALPHABET = ANY_IUPAC + GAP_IUPAC + MISSING_IUPAC
ANY_ALPHABET = ANY + GAP + MISSING

#CODONS
DNA_STANDARD_IUPAC_CODONS = tuple([i + j + k for i in DNA_STANDARD_IUPAC
                                             for j in DNA_STANDARD_IUPAC
                                             for k in DNA_STANDARD_IUPAC])
RNA_STANDARD_IUPAC_CODONS = tuple([i + j + k for i in RNA_STANDARD_IUPAC
                                             for j in RNA_STANDARD_IUPAC
                                             for k in RNA_STANDARD_IUPAC])


AA_TO_STANDARD = \
    {
    ('A',):('A',),
    ('B',):('D',), # D > N
    ('C',):('C',),
    ('D',):('D',),
    ('E',):('E',),
    ('F',):('F',),
    ('G',):('G',),
    ('H',):('H',),
    ('I',):('I',),
    ('J',):('L',), # L > I
    ('K',):('K',),
    ('L',):('L',),
    ('M',):('M',),
    ('N',):('N',),
    ('O',):('K',),
    ('P',):('P',),
    ('Q',):('Q',),
    ('R',):('R',),
    ('S',):('S',),
    ('T',):('T',),
    ('U',):('C',),
    ('V',):('V',),
    ('W',):('W',),
    ('Y',):('Y',),
    ('Z',):('Q',), # Q > E
    ('X',):(GAP_IUPAC[0],),
    (GAP[0],):(GAP_IUPAC[0],),
    (GAP[1],):(GAP_IUPAC[0],),
    (MISSING[0],):(GAP_IUPAC[0],),
    (STOP[0],):(GAP_IUPAC[0],),
    }

DNA_FROM_AMBIGOUS = \
    {
    ('T',):(('T',),),
    ('C',):(('C',),),
    ('A',):(('A',),),
    ('G',):(('G',),),
    ('N',):(('T',), ('C',), ('A',), ('G',)),
    ('R',):(('A',), ('G',)),
    ('Y',):(('T',), ('C',)),
    ('W',):(('T',), ('A',)),
    ('S',):(('C',), ('G',)),
    ('K',):(('T',), ('G',)),
    ('M',):(('C',), ('A',)),
    ('B',):(('T',), ('C',), ('G',)),
    ('D',):(('T',), ('A',), ('G',)),
    ('H',):(('T',), ('C',), ('A',)),
    ('V',):(('C',), ('A',), ('G',))
    }

RNA_FROM_AMBIGOUS = \
    {
    ('U',):(('U',),),
    ('C',):(('C',),),
    ('A',):(('A',),),
    ('G',):(('G',),),
    ('N',):(('U',), ('C',), ('A',), ('G',)),
    ('R',):(('A',), ('G',)),
    ('Y',):(('U',), ('C',)),
    ('W',):(('U',), ('A',)),
    ('S',):(('C',), ('G',)),
    ('K',):(('U',), ('G',)),
    ('M',):(('C',), ('A',)),
    ('B',):(('U',), ('C',), ('G',)),
    ('D',):(('U',), ('A',), ('G',)),
    ('H',):(('U',), ('C',), ('A',)),
    ('V',):(('C',), ('A',), ('G',))
    }

DNA_TO_AMBIGOUS = \
    {
    ('A',):(('A',), ('D',), ('H',), ('M',), ('R',), ('V',), ('W',)),
    ('C',):(('C',), ('B',), ('H',), ('M',), ('S',), ('V',), ('Y',)),
    ('G',):(('G',), ('B',), ('D',), ('K',), ('R',), ('S',), ('V',)),
    ('T',):(('T',), ('B',), ('D',), ('H',), ('K',), ('Y',), ('W',)),
    }

RNA_TO_AMBIGOUS = \
    {
    ('A',):(('A',), ('D',), ('H',), ('M',), ('R',), ('V',), ('W',)),
    ('C',):(('C',), ('B',), ('H',), ('M',), ('S',), ('V',), ('Y',)),
    ('G',):(('G',), ('B',), ('D',), ('K',), ('R',), ('S',), ('V',)),
    ('U',):(('U',), ('B',), ('D',), ('H',), ('K',), ('Y',), ('W',)),
    }

AA_TO_AA3 = \
    {
    ('A',):'Ala',
    ('B',):'Asx',
    ('C',):'Cys',
    ('D',):'Asp',
    ('E',):'Glu',
    ('F',):'Phe',
    ('G',):'Gly',
    ('H',):'His',
    ('I',):'Ile',
    ('J',):'Xle',
    ('K',):'Lys',
    ('L',):'Leu',
    ('M',):'Met',
    ('N',):'Asn',
    ('O',):'Pyl',
    ('P',):'Pro',
    ('Q',):'Gln',
    ('R',):'Arg',
    ('S',):'Ser',
    ('T',):'Thr',
    ('U',):'Sec',
    ('V',):'Val',
    ('W',):'Trp',
    ('X',):'Xaa',
    ('Y',):'Tyr',
    ('Z',):'Glx'}

AA3_TO_AA = \
    {
    'Ala':('A',),
    'Arg':('R',),
    'Asn':('N',),
    'Asp':('D',),
    'Asx':('B',),
    'Cys':('C',),
    'Gln':('Q',),
    'Glu':('E',),
    'Glx':('Z',),
    'Gly':('G',),
    'His':('H',),
    'Ile':('I',),
    'Leu':('L',),
    'Lys':('K',),
    'Met':('M',),
    'Mse':('M',),
    'Phe':('F',),
    'Pro':('P',),
    'Pyl':('O',),
    'Sec':('U',),
    'Ser':('S',),
    'Thr':('T',),
    'Trp':('W',),
    'Tyr':('Y',),
    'Val':('V',),
    'Xaa':('X',),
    'Xle':('J',)}

AA_NAMES = \
    {
    ('A',):'alanine',
    ('B',):'aspartic acid or asparagine',
    ('C',):'cysteine',
    ('D',):'aspartic acid',
    ('E',):'glutamic acid',
    ('F',):'phenylalanine',
    ('G',):'glycine',
    ('H',):'histidine',
    ('I',):'isoleucine',
    ('J',):'leucine or isoleucine',
    ('K',):'lysine',
    ('L',):'leucine',
    ('M',):'methionine',
    ('N',):'asparagine',
    ('O',):'pyrrolysine',
    ('P',):'proline',
    ('Q',):'glutamine',
    ('R',):'arginine',
    ('S',):'serine',
    ('T',):'threonine',
    ('U',):'selenocysteine',
    ('V',):'valine',
    ('W',):'tryptophan',
    ('X',):'unknown',
    ('Y',):'tyrosine',
    ('Z',):'glutamic acid or glutamine',
    }

NT_NAMES = \
    {
    ('A',):'Adenosine',
    ('C',):'Cytidine',
    ('G',):'Guanine',
    ('T',):'Thymidine',
    ('U',):'Uracil',
    ('R',):'G A (puRine)',
    ('Y',):'T C (pYrimidine)',
    ('K',):'G T (Ketone)',
    ('M',):'A C (aMino group)',
    ('S',):'G C (Strong interaction)',
    ('W',):'A T (Weak interaction)',
    ('B',):'G T C (not A) (B comes after A)',
    ('D',):'G A T (not C) (D comes after C)',
    ('H',):'A C T (not G) (H comes after G)',
    ('V',):'G C A (not T, not U) (V comes after U)',
    ('N',):'A G C T (aNy)',
    }

SYMBOL_NAMES = \
    {
    '*':'translation stop',
    '-':'gap',
    '?':'missing',
    }

GENETIC_CODES = (
(1, "Standard",
"FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"---M---------------M---------------M----------------------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(2, "Vertebrate Mitochondrial",
"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSS**VVVVAAAADDEEGGGG",
"--------------------------------MMMM---------------M------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(3, "Yeast Mitochondrial",
"FFLLSSSSYY**CCWWTTTTPPPPHHQQRRRRIIMMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"----------------------------------MM----------------------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(4, "Mold, Protozoan, Coelenterate Mitochondrial & Mycoplasma/Spiroplasma",
"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"--MM---------------M------------MMMM---------------M------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(5, "Invertebrate Mitochondrial",
"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSSSVVVVAAAADDEEGGGG",
"---M----------------------------MMMM---------------M------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(6, "Ciliate, Dasycladacean and Hexamita Nuclear",
"FFLLSSSSYYQQCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"-----------------------------------M----------------------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(9, "Echinoderm and Flatworm Mitochondrial",
"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
"-----------------------------------M---------------M------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(10, "Euplotid Nuclear",
"FFLLSSSSYY**CCCWLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"-----------------------------------M----------------------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(11, "Bacterial and Plant Plastid",
"FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"---M---------------M------------MMMM---------------M------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(12, "Alternative Yeast Nuclear",
"FFLLSSSSYY**CC*WLLLSPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"-------------------M---------------M----------------------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(13, "Ascidian Mitochondrial",
"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNKKSSGGVVVVAAAADDEEGGGG",
"-----------------------------------M----------------------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(14, "Alternative Flatworm Mitochondrial",
"FFLLSSSSYYY*CCWWLLLLPPPPHHQQRRRRIIIMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
"-----------------------------------M----------------------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(15, "Blepharisma Nuclear",
"FFLLSSSSYY*QCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"-----------------------------------M----------------------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(16, "Chlorophycean Mitochondrial",
"FFLLSSSSYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"-----------------------------------M----------------------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(21, "Trematode Mitochondrial",
"FFLLSSSSYY**CCWWLLLLPPPPHHQQRRRRIIMMTTTTNNNKSSSSVVVVAAAADDEEGGGG",
"-----------------------------------M---------------M------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(22, "Scenedesmus obliquus Mitochondrial",
"FFLLSS*SYY*LCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"-----------------------------------M----------------------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG"),

(23, "Thraustochytrium Mitochondrial",
"FF*LSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG",
"--------------------------------M--M---------------M------------",
"TTTTTTTTTTTTTTTTCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAGGGGGGGGGGGGGGGG",
"TTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGGTTTTCCCCAAAAGGGG",
"TCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAGTCAG",)
)


def _make_gc(gc):
    codons = zip(*gc[4:])
    aminos = [((start,), (other,)) for start, other in zip(*gc[2:4])]
    return dict(zip(codons, aminos))

GENETIC_CODE_STANDARD = _make_gc(GENETIC_CODES[0])




#class _Proxy(dict):
#    """
#    A proxy, which maps elements (e.g. symbols or codons) to rank-0 
#    ``numpy.ndarrays``. e.g. ``'A'`` becomes ``array('A', dtype='|S1')``
#    the purpose of doing that is performance and structured element support 
#    (e.g. ``('A','G','T')`` in comparisons and to not include arrays in
#    ``pynchon.core.Entity.metadata``.
#    
#    Arguments:
#    
#        - elements (sequence(s) of elements) Possibly multiple sequences of 
#          elements e.g. ``IUPAC_PROTEIN_STANDARD``.
#    """
#
#    def _add_element(self, element):
#        s1u1 = 'S1' if isinstance(element[0], str) else 'U1'
#        dt = [('i%s' % i, s1u1) for i in xrange(len(element))] \
#                if isinstance(element, tuple) else \
#             s1u1
#        self[element] = np.array(element, dtype=dt)
#
#    def __init__(self, *elements):
#        for els in elements:
#            for element in els:
#                self._add_element(element)
#        dict.__init__(self)
#
#    def __getitem__(self, k):
#        array = super(_Proxy, self).get(k)
#        if array is None:
#            self._add_element(k)
#            return self[k]
#        else:
#            return array


#class _StrMethod(object):
#    """
#    A dictionary, which acts like a string method.
#    """
#    def __init__(self, method, *args, **kwargs):
#        self.method = method
#        self.args = args
#        self.kwargs = kwargs
#    def __getitem__(self, k, *args, **kwargs):
#        return getattr(k, self.method)(*self.args, **self.kwargs)


#NUMPY_PROXY = _Proxy(ALL)
#UPPER = _StrMethod('upper')
#GAP_TO_IUPAC_GAP = _StrMethod('replace', '.', '-')








